﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Meraz.Core.Model
{
    public class MemberRole : IEquatable<MemberRole>
    {
        public MemberRole() { }
        public MemberRole(int id) { ID = id; }
        public MemberRole(string applicationName, string roleName, string userName)
        {
            ApplicationName = applicationName;
            RoleName = roleName;
            UserName = userName;
        }

        public int ID { get; set; }
        public string ApplicationName { get; set; }
        public string RoleName { get; set; }
        public string UserName { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;
            return Equals((MemberRole)obj);
        }
        public override int GetHashCode()
        {
            return ApplicationName.GetHashCode()
                ^ RoleName.GetHashCode()
                ^ UserName.GetHashCode();
        }
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("{");
            builder.AppendFormat("{0}: {1}, ", "ID", ID);
            builder.AppendFormat("{0}: '{1}', ", "ApplicationName", ApplicationName);
            builder.AppendFormat("{0}: '{1}', ", "RoleName", RoleName);
            builder.AppendFormat("{0}: '{1}'", "UserName", UserName);
            builder.Append("}");
            return builder.ToString();
        }

        #region IEquatable<MemberRole> Members

        public bool Equals(MemberRole other)
        {
            if (other == null)
                return false;
            if (!ID.Equals(other.ID)){
                if (ApplicationName != other.ApplicationName)
                    return false;
                if (UserName != other.UserName)
                    return false;
                return RoleName.Equals(other.RoleName);
            }else
                return true;
        }

        #endregion
    }
}
